<div class="widget-box">
    <div class="widget-title">
        <span class="icon">
            <i class="icon-th"></i>
        </span>
        <h5>功能列表</h5>
        <!--<span class="label label-info"></span>-->
    </div>
    <div class="widget-content">
        <table class="table table-bordered table-striped with-check">
            <thead>
                <tr>
                    <th><input type="checkbox" id="title-table-checkbox" name="title-table-checkbox" /></th>
                    <th>功能名称</th>
                    <th>功能类型</th>
                    <th>所属角色</th>
                    <th>功能说明</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <?php
                $eventCooker = new BAEventCooker();
                $roleCooker = new BARoleCooker();
                foreach ($userEventList as $id => $list) {
                    $userEventData = $list->getItemsInArray();
                    $eventId = $userEventData['eventId'];
                    $roleId = $userEventData['roleId'];
                    $allowModify = isset($userEventData['allowModify']) && $userEventData['allowModify'] == 'yes' ? TRUE : NULL;
                    $allowDelete = isset($userEventData['allowDelete']) && $userEventData['allowDelete'] == 'yes' ? TRUE : NULL;
                    $eventHome = isset($userEventData['eventHome']) ? $userEventData['eventHome'] : NULL;
                    $eventHomeTitle = isset($userEventData['eventHomeTitle']) ? $userEventData['eventHomeTitle'] : '功能首页';
                    if ($eventHome == NULL && $allowDelete == NULL && $allowDelete == NULL) {
                        continue;
                    }
                    $mobileTheme = isset($userEventData['mobileTheme']) ? $userEventData['mobileTheme'] : NULL;
                    $role = new BRole($roleId);
                    $event = $eventCooker->getEvent($eventId);
                    $eventType = $eventCooker->getEventTypeByEvent($event);
                    if ($event->getItem('alias') != NULL)
                        $eventName = $event->getItem('alias')->getValue();
                    else
                        $eventName = $event->getItem('name')->getValue();
                    //$changelessEventType = $eventType->getRootNode()->getChild('eventType.changeless');
                    $eventTypeAlias = $eventCooker->getEventTypeAlias($eventType);
                    if ($eventTypeAlias == NULL) {
                        $eventTypeAlias = $eventType->getValue();
                    }
                    $roleFullName = $role->getFullName();
                    $roleAlias = BARoleCooker::getRoleAliasByFullName($roleFullName);
                    ?>
                    <tr>
                        <td><input type="checkbox" /></td>
                        <td><?php echo $eventName ?></td>
                        <td><?php echo $eventTypeAlias; ?></td>
                        <td><?php echo $roleAlias; ?></td>
                        <td> <?php
                            $descItem = $event->getItem('description');
                            if ($descItem instanceof BTreeList) {
                                echo $event->getItem('description')->getValue();
                            } else {
                                echo Yii::t('site', 'no description');
                            }
                            ?></td>
                        <td>                           <?php
                            $actionString = '';

                            if (isset($userEventData['allowModify']) && $userEventData['allowModify'] == 'yes') {
                                //if (!$eventType->isChildOf($changelessEventType)) {
                                if ($actionString != '') {
                                    $actionString.= " | ";
                                }
                                $actionString.= $control->getAjaxLink(array('name' => '设置功能', 'id' => 'showAddEvent'), array(
                                    'cooker' => 'BAEvent@showAddEvent',
                                    'theme' => 'a_bootstrap',
                                    'eventId' => $eventId
                                ));
                            }
                            if (isset($userEventData['allowDelete']) && $userEventData['allowDelete'] == 'yes') {
                                if ($actionString != '') {
                                    $actionString.= " | ";
                                }
                                $actionString.= $control->getAjaxLink(array('name' => '删除', 'id' => 'deleteEvent'), array(
                                    'cooker' => 'BAEvent@deleteEvent',
                                    'theme' => 'a_bootstrap',
                                    'eventId' => $eventId
                                ));
                            }
                            if ($eventHome != NULL) {
                                if ($actionString != '') {
                                    $actionString.= " | ";
                                }
                                $actionString.= $control->getAjaxLink(array('name' => $eventHomeTitle, 'id' => 'showEventHome'), array(
                                    'cooker' => 'BAEvent@showEventHome',
                                    'theme' => 'a_bootstrap',
                                    'eventId' => $eventId,
                                    'roleId' => $roleId,
                                    'eventHome' => $eventHome
                                ));
                            }
                            if ($mobileTheme != NULL) {
                                if ($actionString != '') {
                                    $actionString.= " | ";
                                }
                                $actionString.= $control->getLink(array('name' => '手机访问', 'id' => 'showEventHome'), array(
                                    'cooker' => 'BAEvent@showEventHome',
                                    'theme' => 'mb_bootstrap',
                                    'eventId' => $eventId,
                                    'roleId' => $roleId,
                                    'eventHome' => $eventHome,
                                    'htmlOptions' => array(
                                        'class' => '', 'target' => '_blank'),
                                ));
                            }
                            if ($actionString != '') {
                                echo $actionString;
                            }
                            //}
//                            echo " | ";
//                                    echo $control->getAjaxLink(array('name' => '帮助', 'id' => 'helpEvent'), array(
//                                        'cooker' => 'BAEvent@helpEvent',
//                                        'eventId' => $eventId
//                                    ));
//                            $wxControl = new BUIEventControl($eventName . 'Client');
//                            echo $wxControl->getLink(array('name' => '帮助', 'id' => 'helpEvent'), array(
//                                'cooker' => 'BAEvent@helpEvent',
//                                'eventId' => $eventId,
//                                'htmlOptions' => array(
//                                    'class' => '', 'target' => '_blank'),
//                                'theme' => 'mb_bootstrap'
//                            ));
                            ?> </td>
                    </tr>
                <?php } ?>
            </tbody>
        </table>							
    </div>
</div>